# _*_coding:utf-8 _*_
# @Time　　:2021/1/18   21:37
# @Author　 : wangyong
# @ File　　  :api_excel.py
# @Software  :PyCharm

from openpyxl import load_workbook


class Excel:
    def __init__(self, filePath, sheetName):
        self.sheetName = sheetName
        self.filePath = filePath
        self.wb = load_workbook(self.filePath)
        self.ws = self.wb.get_sheet_by_name(self.sheetName)

    def read_excel(self):
        data = []
        for i in range(self.ws.max_row + 1):
            dic = {}
            for j in range(self.ws.max_column + 1):
                dic[self.ws.cell(row=1, column=j + 1).value] = self.ws.cell(row=i + 1, column=j).value
            data.append(dic)
        return data

    def write_excel(self, caseID: int, data: str):
        self.ws.cell(row=caseID + 1, column=4).value = data
        self.wb.save(self.filePath)


print(Excel(r"E:\培训\ApiTest\data\api_case.xlsx", "login").read_excel())
